<?php


namespace App\Http\Controllers\Admin;


use App\Tool\Json;

class UploadController extends AuthCheckController
{

    /**
     * @Auth(type='no_check')
     * Create by Peter
     * 2019/09/05 15:31:27
     * Email:904801074@qq.com
     * @return false|string
     */
    function upload()
    {


        $file = request()->file('file');

        # 原文件名
        $originalName = $file->getClientOriginalName();

        # 扩展名
        $ext = $file->getClientOriginalExtension();

        $allowList=env('ALLOW_UPLOAD_TYPE','png,gif,jpg,jpeg');

        $allowList=explode(',',$allowList);

        if(!in_array(strtolower($ext),$allowList)) return Json::code(2,'不允许上传该类型文件');

        # Mimetype
        $type = $file->getClientMimeType();

        # 临时绝对路径
        $realPath = $file->getRealPath();

        # 自定义文件名
        $fileName = date('Ymd') . '/' . uniqid() . '.' . $ext;

        # 选择磁盘
        \Storage::disk('upload')->put($fileName, file_get_contents($realPath));


        return Json::code(1, 'success', $fileName);
    }

}
